package cn.mumzone.pos.model.source;

import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.List;

import cn.mumzone.basic.net.http.callback.ApiCallBack;
import cn.mumzone.basic.net.response.BaseResponse;
import cn.mumzone.basic.net.source.AbsRepository;
import cn.mumzone.basic.util.RxUtil;
import cn.mumzone.pos.api.ApiRequest;
import cn.mumzone.pos.model.DailyReportEntity;
import cn.mumzone.pos.model.ExceptionReportEntity;
import cn.mumzone.pos.model.GoodsClassifyEntity;
import cn.mumzone.pos.model.SalesVolumeEntity;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Response;

/**
 * Created by qiuzhenhuan on 2019/3/22.
 */

public class ReportRepository extends AbsRepository {


    public void getDailyReportByDate(String createTime, ApiCallBack<DailyReportEntity> callBack) {
        ApiRequest.getReportService()
                .getDailyReportByDate(createTime)
                .compose(RxUtil.<Response<BaseResponse<DailyReportEntity>>>applySchedulers())
                .subscribe(callBack);
    }

    public void getSalesVolumeReportByDate(String time, String classifyOne, String classifyTwo, String classifyThree, String orderType, ApiCallBack<List<SalesVolumeEntity>> callBack) {

        HashMap<String, String> requestMap = new HashMap<>();
        requestMap.put("time", time);
        requestMap.put("classifyOne", classifyOne);
        requestMap.put("classifyTwo", classifyTwo);
        requestMap.put("classifyThree", classifyThree);
        requestMap.put("orderType", orderType);
        requestMap.put("pageNum", "1");
        requestMap.put("pageSize", "20");
        ApiRequest.getReportService()
                .getSalesVolumeReportByDate(requestMap)
                .compose(RxUtil.<Response<BaseResponse<List<SalesVolumeEntity>>>>applySchedulers())
                .subscribe(callBack);
    }

    public void getExceptionReportByDate(String startTime, String endTime, ApiCallBack<ExceptionReportEntity> callBack) {
        ApiRequest.getReportService()
                .getExceptionReportByDate(startTime, endTime)
                .compose(RxUtil.<Response<BaseResponse<ExceptionReportEntity>>>applySchedulers())
                .subscribe(callBack);
    }


    public void getGoodsClassify(String primaryClassify, String secondaryClassify, String threeClassify, ApiCallBack<List<GoodsClassifyEntity>> callBack) {
        HashMap<String, String> requestMap = new HashMap<>();
        requestMap.put("primaryClassify", primaryClassify);
        requestMap.put("secondaryClassify", secondaryClassify);
        requestMap.put("threeClassify", threeClassify);
        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), JSON.toJSONString(requestMap));
        ApiRequest.getReportService()
                .getGoodsClassify(body)
                .compose(RxUtil.<Response<BaseResponse<List<GoodsClassifyEntity>>>>applySchedulers())
                .subscribe(callBack);
    }
}
